package engine.display.Story.ActionItem 
{
	import engine.display.Story.ActionControl.TimerTextField;
	import engine.display.Story.StoryMoveEvent.StoryEvent;
	import engine.display.Story.StoryVo;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.text.TextFormat;
	import flash.utils.Timer;
	
	/**
	 * ...黑幕动画类型
	 * @author WangHaiBo  www.woniu.com
	 */
	public class BlackTalkInfoUI extends BaseAction
	{
		private var backBG:Sprite
		private var infoText:TimerTextField;
		private static var _self:BlackTalkInfoUI
		private var timer:Timer;
		private var timerNum:int	=	100;
		private var strIndex:int	=	0;
		private var showStr:String	=	"";
		private var textFormat:TextFormat;
		private var alphaMax:int	=	100;
		public function BlackTalkInfoUI() 
		{
			Init();
		}
		public static function getInstance():BlackTalkInfoUI
		{
			if (_self == null)
			{
				_self	=	new BlackTalkInfoUI();
			}
			return _self
		}
		private function Init():void
		{
			timer			=	new Timer(timerNum);
			infoText		=	new TimerTextField();
			backBG			=	new Sprite();
			textFormat		=	new TextFormat();
			
			backBG.graphics.beginFill(0x000000);
			backBG.graphics.drawRect(0, 0, 1280,768);
			backBG.graphics.endFill();
			
			infoText.selectable		=	false;
			textFormat.bold			=	true;
			textFormat.size			=	24;
			textFormat.color		=	0xFFFF00;
			infoText.width			=	600;
			infoText.height			=	200;
			infoText.x				=	200;
			infoText.y				=	200;
			infoText.timerlenght	=	100;
			infoText.wordWrap		=	true
			infoText.defaultTextFormat	=	textFormat;
			infoText.setTextFormat(textFormat);
			infoText
			this.addChild(backBG);
			this.addChild(infoText);
			infoText.addEventListener(StoryEvent.TEXT_OVER, talkOverHandle)
			timer.addEventListener(TimerEvent.TIMER,timerHandle)
		}
		
		private function timerHandle(e:TimerEvent):void 
		{
			alphaMax-=10;
			this.alpha 	=	alphaMax / 100;
			if (alphaMax <= 0) 
			{
				this.alpha	=	0;
				timer.stop();
				actionOver();
			}
		}
		/**
		 * 文字动画完成了
		 * @param	e
		 */
		private function talkOverHandle(e:StoryEvent):void 
		{
			timer.start();
		}
		override public function showInfo(val:StoryVo):void 
		{
			alphaMax	=	100
			this.alpha	=	1
			infoText.text	=	val.TalkInfo
		}
		/**
		 * 场景尺寸改变
		 */
		public function changeLocation(stageWidth:int,stageHeight:int):void
		{
			backBG.width	=	stageWidth;
			backBG.height	=	stageHeight;
			infoText.x		=	(backBG.width - 600) * .5;
		}
	}

}